/*
 * Copyright (c) 2025 Li Auto Inc. and its affiliates
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EDDS_RTPS_COMMON_CDRSERIALIZATION_HPP
#define EDDS_RTPS_COMMON_CDRSERIALIZATION_HPP

#include <ecdr/Cdr.h>

#if FASTCDR_VERSION_MAJOR == 1

#include <ecdr/exceptions/BadParamException.h>
#include <ertps/utils/fixed_size_string.hpp>

namespace vbsutil {
namespace ecdr {

namespace CdrVersion {
const vbsutil::ecdr::Cdr::CdrType DDS_CDR = vbsutil::ecdr::Cdr::CdrType::DDS_CDR;
const vbsutil::ecdr::Cdr::CdrType XCDRv1 = vbsutil::ecdr::Cdr::CdrType::DDS_CDR;
const vbsutil::ecdr::Cdr::CdrType XCDRv2 = vbsutil::ecdr::Cdr::CdrType::DDS_CDR;
}  // namespace CdrVersion

class CdrSizeCalculator;

template <class _T>
extern size_t calculate_serialized_size(vbsutil::ecdr::CdrSizeCalculator& calculator, const _T& data,
                                        size_t& current_alignment);

template <class _T>
extern void serialize(Cdr&, const _T&);

template <class _T>
extern void deserialize(Cdr&, _T&);

// Dummy class
class CdrSizeCalculator {
 public:
    CdrSizeCalculator(vbsutil::ecdr::Cdr::CdrType) {}

    template <class _T>
    size_t calculate_serialized_size(const _T& data, size_t current_alignment) {
        return vbsutil::ecdr::calculate_serialized_size(*this, data, current_alignment);
    }
};

template <size_t MAX_CHARS>
using fixed_string = evbs::ertps::fixed_string<MAX_CHARS>;

}  // namespace ecdr
}  // namespace vbsutil

namespace evbs {
namespace edds {
namespace rtps {
//! Default XCDR encoding version used in Fast DDS.
constexpr vbsutil::ecdr::Cdr::CdrType DEFAULT_XCDR_VERSION {vbsutil::ecdr::Cdr::CdrType::DDS_CDR};
}  // namespace rtps
}  // namespace edds
}  // namespace evbs

#else

#include <ecdr/CdrSizeCalculator.hpp>

namespace evbs {
namespace edds {
namespace rtps {
//! Default XCDR encoding version used in EVBS.
constexpr vbsutil::ecdr::CdrVersion DEFAULT_XCDR_VERSION {vbsutil::ecdr::CdrVersion::XCDRv1};
}  // namespace rtps
}  // namespace edds
}  // namespace evbs

#endif  //FASTCDR_VERSION_MAJOR == 1

#endif  // EDDS_RTPS_COMMON_CDRSERIALIZATION_HPP
